#ifndef __BASIC_H__
#define __BASIC_H__

#include "main.h"
#include "uart.h"
#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C"
{
#endif

    void LOGI(const char *tag, const char *str);

    typedef struct
    {
        GPIO_TypeDef *port;
        uint16_t pin;
    } gpio_t;

    uint32_t get_ms();
    uint32_t get_us();

    void delay(uint32_t ms);
    void delay_us(uint32_t us);

    void print_float(float f, uint8_t precision);
    void print_int(int64_t i);
    void print_uint(uint64_t i);
    float fabsf(float f);

#define _max(a, b) ((a) > (b) ? (a) : (b))
#define _min(a, b) ((a) < (b) ? (a) : (b))

#define __PERIOD(name, period_ms, excute_body)              \
    static uint32_t name##_last_time = 0;                   \
    uint32_t name##_delta_ms = get_ms() - name##_last_time; \
    if (name##_delta_ms >= period_ms)                       \
    {                                                       \
        name##_last_time = get_ms();                        \
        excute_body;                                        \
    }
#define __GET_PERIOD_DELTA_MS(name) name##_delta_ms

#ifdef __cplusplus
}
#endif // __cplusplus



#endif // __BASIC_H__
